package com.client;

import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RadioButton;

public class DateFormatter extends HorizontalPanel {
	private RadioButton rbYear;
	private RadioButton rbMonth;
	private RadioButton rbDay;
	private RadioButton rbHour;
	private RadioButton rbMinute;
	private RadioButton rbSecond;
	private CheckBox cbFullDate;

	protected void onAttach() {
		this.rbYear = new RadioButton("DFmt", CNStatsFront.get().constants.year());
		this.rbMonth = new RadioButton("DFmt", CNStatsFront.get().constants.month());
		this.rbDay = new RadioButton("DFmt", CNStatsFront.get().constants.day());
		this.rbHour = new RadioButton("DFmt", CNStatsFront.get().constants.hour());
		this.rbMinute = new RadioButton("DFmt", CNStatsFront.get().constants.minute());
		this.rbSecond = new RadioButton("DFmt", CNStatsFront.get().constants.second());
		this.cbFullDate = new CheckBox(CNStatsFront.get().constants.fullDate());
		this.add(rbYear);
		this.add(rbMonth);
		this.add(rbDay);
		this.add(rbHour);
		this.add(rbMinute);
		this.add(rbSecond);
		this.add(cbFullDate);
		this.rbYear.setValue(true);
		this.cbFullDate.setValue(true);
		super.onAttach();
	}
	
	public String getDateFormat() {
		String dfmt = ""; //%Y%m%d%H%M%S
		if (true == this.rbYear.getValue()) {
			dfmt = "%Y";
		}
		else if (true == this.rbMonth.getValue()) {
			if (true == this.cbFullDate.getValue()) {
				dfmt = "%Y";
			}
			dfmt += "%m";
		}
		else if (true == this.rbDay.getValue()) {
			if (true == this.cbFullDate.getValue()) {
				dfmt = "%Y%m";
			}
			dfmt += "%d";
		}
		else if (true == this.rbHour.getValue()) {
			if (true == this.cbFullDate.getValue()) {
				dfmt = "%Y%m%d";
			}
			dfmt += "%H";
		}
		else if (true == this.rbMinute.getValue()) {
			if (true == this.cbFullDate.getValue()) {
				dfmt = "%Y%m%d%H";
			}
			dfmt += "%M";
		}
		else if (true == this.rbSecond.getValue()) {
			if (true == this.cbFullDate.getValue()) {
				dfmt = "%Y%m%d%H%M";
			}
			dfmt += "%S";
		}
		return dfmt;
	}

	public void reset() {
		this.rbYear.setValue(true);
		this.cbFullDate.setValue(true);
	}
}
